package _interface

import (
	"fmt"
	"gitee.com/garychou/diploma-project/configs"
	"github.com/gin-gonic/gin"
	"go.uber.org/config"
)

var (
	App        string
	Port       string
	ConfigPath string = "interface.yaml"
)

// Run /启动BFF
func Run() {
	//获取配置
	yaml, err := config.NewYAML(config.File(fmt.Sprintf("%s%s", configs.GetConfig().GetBasePath(), ConfigPath)))
	if err != nil {
		panic(fmt.Errorf("config配置文件获取失败，Err: %v", err))
	}
	App = yaml.Get("app").String()
	Port = yaml.Get("port").String()
	ginMode := yaml.Get("gin-mode").String()

	//加载gin
	gin.SetMode(ginMode)
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	if err = r.Run(fmt.Sprintf(":%s", Port)); err != nil {
		panic(fmt.Errorf("%s服务启动失败，Err: %v", App, err))
	}
}
